package de.wtschreiter.structured.document.io.event.basic;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.*;

import de.wtschreiter.structured.document.io.event.*;

public class BasicStartElementEvent extends AbstractBasicAttributedEvent implements StartElementEvent {

    private String name;
    private String namespace;

    public BasicStartElementEvent() {
        super(EventType.START_ELEMENT);
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder() //
                .append(super.hashCode()) //
                .append(namespace) //
                .append(name) //
                .toHashCode();
    }

    @Override
    public boolean equals(final Object obj) {
        if (super.equals(obj)) {
            return true;
        }
        if (!(obj instanceof StartElementEvent)) {
            return false;
        }
        final StartElementEvent other = (StartElementEvent) obj;
        return new EqualsBuilder() //
                .append(getNamespace(), other.getNamespace()) //
                .append(getName(), other.getName()) //
                .appendSuper(hasSameAttribures(other)) //
                .isEquals();
    }

    @Override
    public String toString() {
        final ToStringBuilder toStringBuilder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
        toStringBuilder.append("namespace", getNamespace()) //
                .append("name", getName());
        return appendAttributes(toStringBuilder).toString();
    }

    @Override
    public String getName() {
        return StringUtils.defaultString(name);
    }

    public void setName(final String name) {
        this.name = name;
    }

    @Override
    public String getNamespace() {
        return StringUtils.defaultString(namespace);
    }

    public void setNamespace(final String namespace) {
        this.namespace = namespace;
    }

}
